package users;

import java.util.ArrayList;
import java.util.Date;
import java.io.Serializable;

/**
 * 
 * @author Evgeny Pavlenko
 * 
 */

public class User implements Comparable, Serializable {
	private final static int USER = 1;
	private final static int ADMIN = 2;
	private String name;
	private String password;
	private int accessLevel;
	private ArrayList<String> score;

	public User(String name, String password) {
		this.name = name;
		this.password = password;
		this.accessLevel = USER;
		score = new ArrayList<String>();
	}

	public boolean checkPassword(String password) {
		return this.password.equals(password);
	}

	public String getName() {
		return name;
	}

	public String getScore() {
		return score.toString();
	}

	public boolean isAdmin() {
		return accessLevel == ADMIN;
	}

	public void assignAdmin() {
		accessLevel = ADMIN;
	}

	public void assignUser() {
		accessLevel = USER;
	}

	public void setScore(int score) {
		String string = String.format("\n%1$s %2$tB %2$te, %2$tY %3$s %4$d",
				"Дата:", new Date(), " Score:", score);
		this.score.add(string);
	}

	@Override
	public int compareTo(Object o) {
		return name.compareTo(((User) o).getName());
	}

}
